<template>
	<view class="movie-list">
		<view 
		class="list-item" 
		v-for="item in movieList" 
		:key="item.id"
		:id="item.id"
		@tap="toMovieDetail"
		>
			<image :src="item.cover" mode=""></image>
			<text>{{item.title}}</text>
		</view>
	
		
	</view>
	
</template>

<script>
	import request from '../../utils/request.js'
	export default {
		data() {
			return {
				movieList:[],
				pageData:{
					pageSize:12,
					currentPage:1
				},
				tag:''
			}
		},
		onLoad(options) {
			this.tag = options.tag;
			this.getMoviesDataBy();
		},
		onReachBottom() {			
			uni.showLoading({
				title:'加载中'
			})
			
			setTimeout(()=>{
				this.pageData.currentPage++;
				this.getMoviesDataBy();
				uni.hideLoading();
			},500)
	
		},
		methods: {
			async getMoviesDataBy() {
				let query = {
					tag:this.tag,
					...this.pageData
				};
				let moviesData = await request('/movies/getMovies', query);
				if(moviesData.code){
					this.movieList =  [...this.movieList, ...moviesData.result.rows];
					// console.log(this.movieList);
				}
			},
			
			toMovieDetail(e){
				uni.navigateTo({
					url: '../../pages/movie-detail/movie-detail?id=' + e.currentTarget.id
				})
			},
		}
	}
</script>

<style scoped lang="scss">
.movie-list{
	display: flex;
	flex-wrap: wrap;
	padding: 50rpx;
	box-sizing: border-box;
	.list-item{
		display: flex;		flex-direction: column;	
		align-items: center;
		margin-right: 84rpx;
		margin-bottom: 40rpx;
		&:nth-of-type(3n){
			margin-right: 0;
		}
		image{
			width: 160rpx;
			height: 225rpx;
			border-radius: 20rpx;
		}
		text{
			width: 160rpx;
			font-size: 26rpx;
			text-align: center;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
		}
	}
}


</style>
